package com.neusoft.controller;

import com.neusoft.po.CommonResult;
import com.neusoft.po.Deliveryman;
import com.neusoft.po.Orders;
import com.neusoft.sevice.DeliverymanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/DeliverymanController")
@RefreshScope       //开启动态刷新
public class DeliverymanController {
    @Autowired
    private DeliverymanService deliverymanService;
    @GetMapping("/listNonAcceptedOrders")
    public CommonResult<List<Orders>> listNonAcceptedOrders() throws Exception{
        List<Orders> list = deliverymanService.listNonAcceptedOrders();
        return new CommonResult<>(200,"success",list);
    }
    @GetMapping("/listAcceptedOrderByDeliverymanId/{userId}")
    public CommonResult<List<Orders>> listAcceptedOrderByDeliverymanId(@PathVariable("userId")String userid)
            throws Exception{
        List<Orders> list = deliverymanService.listAcceptedOrderByDeliverymanId(userid);
        return new CommonResult<>(200,"success",list);
    }
    @PutMapping("/OrdersAccepted/{OrderNumber}/{userId}")
    public CommonResult<Integer> AcceptedOrders(@PathVariable("OrderNumber") Integer OrderNumber, @PathVariable("userId") String userId)
            throws Exception{

        int result = deliverymanService.AcceptedOrders(OrderNumber, userId);
        return new CommonResult<>(200,"success",result);
    }
    @PutMapping("/OrdersFinished/{OrderNumber}")
    public CommonResult<Integer> FinishedOrders(@PathVariable("OrderNumber") Integer OrderNumber)
            throws Exception{

        int result = deliverymanService.FinishedOrders(OrderNumber);
        return new CommonResult<>(200,"success",result);
    }

}
